
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>编辑页面</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/style/custom.css}" media="all">
</head>
<body>

  <div class="layui-form" lay-filter="app-info-form-edit" id="app-info-form-edit" style="padding: 20px 30px 0 0;">
    <input type="hidden" id="id" name="id" th:value="${applicationInfo.id}"/>
    <div class="layui-form-item">
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <label class="layui-form-label">应用名称</label>
        <div class="layui-input-block">
          <input type="text" name="appName" th:value="${applicationInfo.appName}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
        </div>
      </div>
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <label class="layui-form-label">AppID</label>
        <div class="layui-input-block">
          <input type="text" name="appId" th:value="${applicationInfo.appId}" readonly placeholder="请输入" autocomplete="off" class="layui-input" />
        </div>
      </div>
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <label class="layui-form-label">应用KEY</label>
        <div class="layui-input-block">
          <input type="text" name="appKey" th:value="${applicationInfo.appKey}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <label class="layui-form-label">域名主机</label>
        <div class="layui-input-block">
          <input type="text" name="host" th:value="${applicationInfo.host}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
        </div>
      </div>
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <label class="layui-form-label">端口号</label>
        <div class="layui-input-block">
          <input type="text" name="port" th:value="${applicationInfo.port}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
        </div>
      </div>
<!--    </div>-->
<!--    <div class="layui-form-item">-->
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <div class="layui-inline" style="width: 100%;">
          <label class="layui-form-label">应用密钥</label>
          <div class="layui-input-inline" style="width: 60%;">
            <input type="text" name="appSecret" th:value="${applicationInfo.appSecret}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
          </div>
          <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" style="margin-top: 4px;" lay-on="get-secret"><i class="layui-icon layui-icon-refresh"></i>刷新密钥</button>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <label class="layui-form-label">开始日期</label>
        <div class="layui-input-block">
          <input type="text" id="startDate" name="startDate" th:value="${applicationInfo.startDate}" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <label class="layui-form-label">结束日期</label>
        <div class="layui-input-block">
          <input type="text" id="endDate" name="endDate" th:value="${applicationInfo.endDate}" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <div class="layui-inline" style="width: 100%;">
          <label class="layui-form-label"></label>
          <div class="layui-input-inline">
            <input type="radio" name="keyAe" value="RSA" title="RSA" th:checked="${ applicationInfo.keyAe == 'RSA'} ? true">
            <input type="radio" name="keyAe" value="SM2" title="SM2" th:checked="${ applicationInfo.keyAe == null || applicationInfo.keyAe == 'SM2'} ? true">
          </div>
          <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" style="margin-top: 4px;" lay-on="get-pair"><i class="layui-icon layui-icon-key"></i>生成平台公私钥</button>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">平台公钥</label>
      <div class="layui-input-block">
        <textarea name="pubKey" placeholder="请输入内容" th:text="${applicationInfo.pubKey}" class="layui-textarea"></textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">平台私钥</label>
      <div class="layui-input-block">
        <textarea name="priKey" placeholder="请输入内容" th:text="${applicationInfo.priKey}" class="layui-textarea"></textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
        <div class="layui-inline" style="width: 100%;">
          <label class="layui-form-label"></label>
          <div class="layui-input-inline">
            <input type="radio" name="keySe" value="DES" title="DES" th:checked="${ applicationInfo.keySe == 'DES'} ? true">
            <input type="radio" name="keySe" value="SM4" title="SM4" th:checked="${ applicationInfo.keySe == null || applicationInfo.keySe == 'SM4'} ? true">
          </div>
          <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" style="margin-top: 4px;" lay-on="get-key"><i class="layui-icon layui-icon-key"></i>生成平台密钥</button>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">平台密钥</label>
      <div class="layui-input-block">
        <input type="text" name="secretKey" placeholder="请输入内容" th:value="${applicationInfo.secretKey}" class="layui-input"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">应用公钥</label>
      <div class="layui-input-block">
        <textarea name="appPubKey" placeholder="请输入内容" th:text="${applicationInfo.appPubKey}" class="layui-textarea"></textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">应用密钥</label>
      <div class="layui-input-block">
        <input type="text" name="appSecretKey" placeholder="请输入内容" th:value="${applicationInfo.appSecretKey}" class="layui-input"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">IP白名单</label>
      <div class="layui-input-block">
        <input type="text" name="ipInfo" placeholder="请输入内容" th:value="${applicationInfo.ipInfo}" class="layui-input"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-block">
        <input type="radio" name="status" value="Y" title="启用" th:checked="${ applicationInfo.status == null || applicationInfo.status == 'Y'} ? true">
        <input type="radio" name="status" value="N" title="禁用" th:checked="${ applicationInfo.status == 'N'} ? true">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">备注</label>
      <div class="layui-input-block">
        <textarea name="remark" placeholder="请输入内容" th:text="${ applicationInfo.remark }" class="layui-textarea"></textarea>
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="LAY-app-info-front-submit" id="LAY-app-info-front-submit" value="确认">
    </div>
  </div>

  <script th:src="@{/layui/layui.js}"></script>
  <script>
    layui.config({
      base: '/'
    }).use(['index'], function () {
      const $ = layui.$
        ,admin = layui.admin
        ,form = layui.form
        ,table = layui.table
        ,layer = layui.layer
        ,dropdown = layui.dropdown
        ,util = layui.util
        ,flying = layui.flying;

      layui.laydate.render({
        elem: '#startDate' //指定元素
        , trigger: 'click'
        , format: 'yyyy-MM-dd'
        , type: 'date'
      });

      layui.laydate.render({
        elem: '#endDate' //指定元素
        , trigger: 'click'
        , format: 'yyyy-MM-dd'
        , type: 'date'
      });

      // 普通事件
      util.on('lay-on', {
        // 获取密钥
        "get-secret": function(othis){
          //提交 Ajax 成功后，静态更新表格中的数据
          admin.req({
            url: '/esb/application/getSecret' ,
            type: 'post',
            success: function (res) {
              //执行成功
              layer.msg(res.msg, {icon: 1});
              form.val('app-info-form-edit', {
                "appSecret" : res.data
              });
            }
          });
        },
        // 获取平台公私钥对
        "get-pair": function(othis){
          let data = form.val("app-info-form-edit");
          //提交 Ajax 成功后，静态更新表格中的数据
          admin.req({
            url: '/esb/application/getSecret?type=' + data.keyAe + '&appId=' + data.appId,
            type: 'post',
            success: function (res) {
              //执行成功
              layer.msg(res.msg, {icon: 1});
              form.val('app-info-form-edit', {
                "pubKey" : res.data.pub,
                "priKey" : res.data.pri,
              });
            }
          });
        },
        // 获取平台密钥
        "get-key": function(othis){
          let data = form.val("app-info-form-edit");
          //提交 Ajax 成功后，静态更新表格中的数据
          admin.req({
            url: '/esb/application/getSecret?type=' + data.keySe + '&appId=' + data.appId,
            type: 'post',
            success: function (res) {
              //执行成功
              layer.msg(res.msg, {icon: 1});
              form.val('app-info-form-edit', {
                "secretKey" : res.data
              });
            }
          });
        }
      });

    });
  </script>
</body>
</html>